home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-15 | 9.6 KB | 292 lines | [TEXT/ttxt] |
-
- Monday, February 15, 1993 10:40:57 AM
- mac.programmer Item
- From: Michael Hecht,Michael_Hecht@mac.sas.com,Internet
- Subject: Re: Hidden Applications
- To: mac.programmer
- In article <1lhan6INNhuc@newsstand.cit.cornell.edu> Dave Irwin,
- dki1@cornell.edu writes:
- >For a program I'm working on I'd like to be able to launch an
- >application and then "hide" it, in a manner similar to the way the OS
- >hides an app when the user chooses "Hide..." from the application menu.
- >Is there any way to tell the OS to hide an app, or to duplicate this
- >effect? (Note that the apps I'm launching won't have any ability to
- >hide themselves.)
-
- What you need is info on the undocumented "Layer Manager". Each
- application has a "layer" which is similar to a window. In fact, you can
- use the HideWindow and ShowWindow calls on a layer to do what you want.
- The layer's "visible" field tells you if the layer is showing or hidden.
-
- Someone (noted below) previously posted some info they had uncovered on
- the Layer Manager. I've taken that info and expanded & corrected it. The
- C header file below should help you do what you want. This header file
- only describes the more interesting selectors.
-
- The ones I left out do things like create a new layer, construct an
- update event for a layer, collect a layer's window's structure regions
- together, etc., etc.
-
- I redefined the LayerRecord based on a WindowRecord, remapping the window
- fields to their counterparts in a layer.
-
- I discovered that there seems to be a layer whose elements are not
- windows, but the layers of all running processes. I called this a
- metaLayer, and discovered that a layer with the goAwayFlag set indicates
- a metaLayer. Each process' layer has this metaLayer as a parent, and this
- metaLayer has another metaLayer as its parent (I don't know why). This
- metaLayer seems to be topmost, as its parent is NIL. I called this
- topmost layer the deskLayer, since it seems to describe the entire
- desktop.
-
- I also found a neat routine that calls back an action proc for each
- window of each layer. I called this ForEachLayerWindowDo. I'm a bit hazy
- on the first three parameters--they seem to describe the bounds of the
- search. I think they're a starting layer, a starting window, and maybe a
- parent layer, but I'm not quite sure how they interact. It seems you're
- able to pass -1, 0, or an actual LayerPtr or WindowPtr for them. Let me
- know what you discover!
-
- Anyway, here's the H file, plus a sample routine that uses
- ForEachLayerWindowDo to locate the layer belonging to a given PSN.
-
- Good luck!
- --Michael
-
- =======================================================================
- Michael P. Hecht | Internet: Michael_Hecht@mac.sas.com
- SAS Institute Inc.; Cary, NC USA | AppleLink: SAS.HECHT
-
-
- ============begin LayerMgr.h=================
- #ifndef __LAYERMGR__
- #define __LAYERMGR__
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
-
- //Subject: UNofficial description of 2 Layer Manager calls
- //From: Hugues Marty, hugues@isoftfr.isoft.fr
- //Date: 28 Aug 92 08:11:24 GMT
- //
- //
- //
- //This post contains a header and an example of how to use some calls of
- //the UNDOCUMENTED (as long as I know) Layer Manager which comes along
- //with System 7. Of course, this is NOT an official document, and is
- //here for information only. I don't have News access at the moment (I'm
- //sending this via e-mail), so please send mail me copies if you post
- //follow-ups.
- //
- //PS: it only describes 2 calls of the LayerDispatch trap (0xA829).
- //PPS: seems to work under 7.1 beta.
-
- /* Part of the undocumented Layer Manager structures and calls
- * Information found with the help of MacsBug under MacOS 7.0.
- * Please note that using this information may make your mac
- * explode (hey, this could be a subject for a QuickTime moovie !);
- * so use at your own risks, this may break in the future,
- * etc.. (usual disclaimeer).
- * I only wish that Apple will document this manager in a very near
- * future (let's dream...).
- *
- * What I found was that a layer is associated with each running
- * applications (if it has a user-interface), which groups all
- * windows of that application. This is how you can hide an application
- * (remember 'applications' menu under system 7) and get the list of
- * other applications windows. Have fun.
- *
- * PS : If you have more information on the Layer Manager, please
- * let me know! You can join me at hugues@isoft.fr
- */
-
- // 11FEB93 Added descriptions of several more selectors;
- // other minor improvements.
- // Michael Hecht, Michael_Hecht@mac.sas.com
-
- // The _LayerDispatch trap
- #define _LayerDispatch 0xA829
-
- // LayerRecord is similar to a WindowRecord.
- typedef WindowPtr LayerPtr;
-
- // This records some information on the process which owns
- // the layer... Most of it is not clear (there are pointers
- // to other LayerRecords, to a heap zone, etc. in the unknown
- // parts)
- typedef struct {
- long unknown1;
- OSType signature; // The process sig.
- OSType creator; // The process creator
- char unknown2[24];
- ProcessSerialNumber layerPSN; // The process PSN
- char unknown3[40];
- Handle moreLayerInfo; // This handle is 212 bytes sized.
- } LayerInfo, *LayerInfoPtr;
-
- typedef struct {
- GrafPort port; // txSize == 0xDEAD
- short windowKind;
- Boolean visible; // the layer's visibility: HideWindow
- Boolean hilited;
- Boolean metaLayer; // a layer of layers
- Boolean spareFlag;
- RgnHandle strucRgn;
- RgnHandle contRgn;
- RgnHandle updateRgn;
- Handle windowDefProc;
- LayerPtr parentLayer; // layer of which this is a member
- AuxWinHandle auxWinHead; // this layer's AuxWinHead
- short titleWidth;
- AuxCtlHandle auxCtlHead; // this layer's AuxCtlHead
- LayerPtr nextLayer; // next layer in the chain
- WindowPtr windowList; // this layer's WindowList
- LayerInfoPtr layerInfo; // this layer's add'l info: GetWRefCon
- } LayerRecord, *LayerPeek;
-
-
- typedef short WindowActionCode;
- enum {
- kNextWindow = 0,
- kNextLayer = 700,
- kBreak
- };
- typedef pascal WindowActionCode ( *LayerActionProcPtr )(
- WindowPtr theWindow, LayerPtr theLayer, long refCon );
- #define kAllLayers ((LayerPtr)-1)
-
- // Call the action proc for each window in each layer
- pascal WindowActionCode ForEachLayerWindowDo(
- LayerPtr layer1, LayerPtr layer2, LayerPtr layer3,
- LayerActionProcPtr layerAction, long refCon ) = { 0x70F8, _LayerDispatch
- };
-
- // Return the window's layer
- pascal LayerPtr WindowLayer( WindowPtr theWindow ) = { 0x70F9,
- _LayerDispatch };
-
- // Return the frontmost visible window in the given layer
- pascal WindowPtr LayerFrontVisibleWindow( LayerPtr theLayer )
- = { 0x70FD, _LayerDispatch };
-
- // Return the frontmost visible window on the desktop
- pascal WindowPtr DeskFrontVisibleWindow( void ) = { 0x70FE,
- _LayerDispatch };
-
- // Return the desktop's layer (contains all other layers)
- pascal LayerPtr DeskLayer( void ) = { 0x70FF, _LayerDispatch };
-
- // Return TRUE if theLayer is really a LayerPtr; return FALSE if it's a
- WindowPtr
- pascal Boolean IsLayer( LayerPtr theLayer ) = { 0x7002, _LayerDispatch };
-
- // Return the current process' layer
- pascal LayerPtr CurrentLayer( void ) = { 0x7003, _LayerDispatch };
-
- // Return the first window of this layer.
- pascal WindowPtr LayerFrontWindow( LayerPtr theLayer ) = { 0x7006,
- _LayerDispatch };
-
- // All-layer version of FindWindow
- pascal short FindLayerWindow( Point where, WindowPtr *foundWindow )
- = { 0x7007, _LayerDispatch };
-
- #define LayerVisible(aLayer) (((LayerPeek)aLayer)->visible)
-
- #endif
- ============end LayerMgr.h=================
-
- ============begin LayerTest.c=================
- #include "LayerMgr.h"
-
-
- // Set to TRUE if _LayerDispatch exists
- extern Boolean gLayersAvailable;
-
- // Parameters to our LayerActionProc
- typedef struct {
- ProcessSerialNumber *findPSN;
- LayerPtr foundLayer;
- } FindLayerParmRec, *FindLayerParmPtr;
-
-
- // FindLayerProcess: a LayerActionProc that looks for a specific PSN
- static pascal WindowActionCode FindLayerProcess(
- WindowPtr theWindow, LayerPtr theLayer, long refCon )
- {
- WindowActionCode code;
- LayerInfoPtr info;
- FindLayerParmPtr p;
- Boolean same;
-
-
- /* Assume we'll be going to the next layer */
- code = kNextLayer;
-
- /* If this window is really a layer, use it and go to the next "window"
- */
- if( IsLayer( theWindow )) {
- theLayer = theWindow;
- code = kNextWindow;
- }
-
- /* If we got a layer... */
- if( theLayer ) {
-
- /* ...with some info */
- info = ( LayerInfoPtr )GetWRefCon( theLayer );
- if( info ) {
-
- /* See if the PSNs match */
- p = ( FindLayerParmPtr )refCon;
- SameProcess( &info->layerPSN, p->findPSN, &same );
- if( same ) {
-
- /* They do; remember the layer and break out */
- p->foundLayer = theLayer;
- code = kBreak;
- }
- }
- }
-
- return code;
- }
-
- /* ProcessLayer: find a process' layer by its PSN */
- LayerPtr ProcessLayer( ProcessSerialNumber *psn )
- {
- FindLayerParmRec p;
-
-
- if( !gLayersAvailable )
- return 0;
-
- p.findPSN = psn;
- p.foundLayer = 0;
-
- ForEachLayerWindowDo( DeskLayer(), kAllLayers, 0, FindLayerProcess, (
- long )&p );
- return p.foundLayer;
- }
- ============end LayerTest.c=================
-
-
- ------ Internet Message Header Follows ------
- Newsgroups: comp.sys.mac.programmer
- Path: uupsi!psinntp!rpi!gatech!concert!sas!mozart.unx.sas.com!studly.mac.sas.com!Michael_Hecht
- From: Michael Hecht <Michael_Hecht@mac.sas.com>
- Subject: Re: Hidden Applications
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <C2FzKG.Bu4@unx.sas.com>
- X-Useragent: Nuntius v1.1.1d17
- Date: Sun, 14 Feb 1993 14:14:40 GMT
- X-Xxdate: Sun, 14 Feb 93 13:56:00 GMT
- X-Xxmessage-Id: <A7A3B9A0FA05050A@studly.mac.sas.com>
- References: <1lhan6INNhuc@newsstand.cit.cornell.edu>
- Nntp-Posting-Host: studly.mac.sas.com
- Organization: SAS Institute Inc.
- Lines: 267
-
-